Repository navigation
Player: voice handle, cooldown, voice cap, seamless loops, mute - #26
Merged
Merged
Conversation
play() now returns a voice { stop(fade?), rate(r), node } instead of the bare
source node (stop() keeps working). Per-sound guards: cooldown (default 30 ms,
compared by start time so delay-spread plays still happen) and voices (default
4, oldest stopped with a fade). loop option; loop: true on a Sound renders a
seamless loop (tail crossfaded into the head) and play() loops it by default.
muted(on?) keeps the volume for unmute; not stored (README one-liner).
Four loop sounds: rain-loop, wind-loop (nature), engine-idle, force-field
(world). sounds.test checks every take at 44.1/48 kHz for a click-free wrap and
an even level; play.test covers the player with a fake AudioContext.
Gallery: loop sounds toggle on click. Player 3.08 kB gzip (limit 3.1 kB,
was 2.9); sizes and counts updated in READMEs, skill, gallery, brand.
# Conflicts: # CHANGELOG.md # skills/plinkfx/SKILL.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A protective player and runtime loops: the two things the UI-sound libraries with traction have (cooldown, voice cap) and no game SFX library has (loops you start and stop at runtime).
API
.stop()on the old return value still works.play(s, { delay: i * 0.1 })sequences still play. Loops are exempt.AudioContext.muted()is not persisted (the README has thelocalStorageone-liner).Loops
loop: trueon a Sound makes the renderer cut the last 0.5 s and crossfade 0.25 s of it into the start, so the last sample runs into the first. Four new sounds:rain-loop,wind-loop(nature),engine-idle,force-field(world), 3.0 s each. The names don't collide with the one-shot sounds that are being added in parallel.Checked in
sounds.test.tsfor every take at 44.1 and 48 kHz: the step at the wrap is below the sound's own 99.9th-percentile sample step (measured: 0.01-0.65 of it), and the 50 ms RMS across the wrap stays within 3 dB of the median. Tonal loops usevary: 0and whole-number frequencies, so the crossfade stays in phase.Size
The player is now 3.12 kB gzip in CI and 3.08 kB locally (was 2.92 / 2.9 kB; CI's gzip comes out about 30 bytes bigger). I got some of that back by packing the WAV header as 32-bit words, building the filters in a loop and merging the caches, but it still doesn't fit in 3 kB. The size-limit is now 3.15 kB for the player and for player + one sound (3.08 kB in CI), and 16 kB for everything (15.69 kB in CI). The docs say 3.1 kB and 15.7 kB. Every size mention is updated: READMEs, package.json, gallery lede + e2e regex, skill, brand text. The sound count is now 184.
plinkfx check(after merging #25)audit()takes aloopflag, and the CLI and MCPcheckpasssound.loop. Loops skip the edge, tail and silence checks (a loop is meant to start and end at full level). Instead a newloop-clickcheck fails a loop when the wrap jumps more than the sound's 99.9th-percentile step.plinkfx check --all: 184 checked, 0 failed. The new check is documented in reference.md.Tests
tests/play.test.ts(new, fake AudioContext): handle, stop fade, rate, delay, cooldown, voices, loops, stopAll, mute.cli.test.ts:loop-clickpasses a whole-cycle tone and fails one cut mid-cycle;check rain-loop engine-idleexits 0.npm run checkandnpx playwright testpass locally.Gallery: loop sounds toggle on click; hover, arrow keys and the tour don't start them.